<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="编号" prop="no">
        <el-input
          v-model="queryParams.no"
          placeholder="请输入编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="索引" prop="idx">
        <el-input
          v-model="queryParams.idx"
          placeholder="请输入索引"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="模块前缀" prop="module">
        <el-input
          v-model="queryParams.module"
          placeholder="请输入模块前缀"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="名称属性名" prop="propNameName">
        <el-input
          v-model="queryParams.propNameName"
          placeholder="请输入名称属性名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="逻辑删除属性名" prop="propNameDel">
        <el-input
          v-model="queryParams.propNameDel"
          placeholder="请输入逻辑删除属性名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="层级编号属性名" prop="propNameNo">
        <el-input
          v-model="queryParams.propNameNo"
          placeholder="请输入层级编号属性名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主键属性名" prop="propNameKey">
        <el-input
          v-model="queryParams.propNameKey"
          placeholder="请输入主键属性名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人属性名" prop="propNameCreateBy">
        <el-input
          v-model="queryParams.propNameCreateBy"
          placeholder="请输入创建人属性名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="唯一键" prop="uniques">
        <el-input
          v-model="queryParams.uniques"
          placeholder="请输入唯一键"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间属性名" prop="propNameCreateTime">
        <el-input
          v-model="queryParams.propNameCreateTime"
          placeholder="请输入创建时间属性名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="属性索引最大值" prop="propIndexMax">
        <el-input
          v-model="queryParams.propIndexMax"
          placeholder="请输入属性索引最大值"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改人属性名" prop="propNameUpdateBy">
        <el-input
          v-model="queryParams.propNameUpdateBy"
          placeholder="请输入修改人属性名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="关系索引最大值" prop="relationIndexMax">
        <el-input
          v-model="queryParams.relationIndexMax"
          placeholder="请输入关系索引最大值"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改时间属性名" prop="propNameUpdateTime">
        <el-input
          v-model="queryParams.propNameUpdateTime"
          placeholder="请输入修改时间属性名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['rva:object:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['rva:object:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['rva:object:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['rva:object:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="objectList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="编号" align="center" prop="no" />
      <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="索引" align="center" prop="idx" />
      <el-table-column label="模块前缀" align="center" prop="module" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="说明" align="center" prop="description" />
      <el-table-column label="名称属性名" align="center" prop="propNameName" />
      <el-table-column label="逻辑删除属性名" align="center" prop="propNameDel" />
      <el-table-column label="层级编号属性名" align="center" prop="propNameNo" />
      <el-table-column label="主键属性名" align="center" prop="propNameKey" />
      <el-table-column label="创建人属性名" align="center" prop="propNameCreateBy" />
      <el-table-column label="唯一键" align="center" prop="uniques" />
      <el-table-column label="创建时间属性名" align="center" prop="propNameCreateTime" />
      <el-table-column label="属性索引最大值" align="center" prop="propIndexMax" />
      <el-table-column label="修改人属性名" align="center" prop="propNameUpdateBy" />
      <el-table-column label="关系索引最大值" align="center" prop="relationIndexMax" />
      <el-table-column label="其他数据" align="center" prop="data" />
      <el-table-column label="修改时间属性名" align="center" prop="propNameUpdateTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['rva:object:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['rva:object:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改对象对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="编号" prop="no">
          <el-input v-model="form.no" placeholder="请输入编号" />
        </el-form-item>
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="索引" prop="idx">
          <el-input v-model="form.idx" placeholder="请输入索引" />
        </el-form-item>
        <el-form-item label="模块前缀" prop="module">
          <el-input v-model="form.module" placeholder="请输入模块前缀" />
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="说明" prop="description">
          <el-input v-model="form.description" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="名称属性名" prop="propNameName">
          <el-input v-model="form.propNameName" placeholder="请输入名称属性名" />
        </el-form-item>
        <el-form-item label="逻辑删除属性名" prop="propNameDel">
          <el-input v-model="form.propNameDel" placeholder="请输入逻辑删除属性名" />
        </el-form-item>
        <el-form-item label="层级编号属性名" prop="propNameNo">
          <el-input v-model="form.propNameNo" placeholder="请输入层级编号属性名" />
        </el-form-item>
        <el-form-item label="主键属性名" prop="propNameKey">
          <el-input v-model="form.propNameKey" placeholder="请输入主键属性名" />
        </el-form-item>
        <el-form-item label="创建人属性名" prop="propNameCreateBy">
          <el-input v-model="form.propNameCreateBy" placeholder="请输入创建人属性名" />
        </el-form-item>
        <el-form-item label="唯一键" prop="uniques">
          <el-input v-model="form.uniques" placeholder="请输入唯一键" />
        </el-form-item>
        <el-form-item label="创建时间属性名" prop="propNameCreateTime">
          <el-input v-model="form.propNameCreateTime" placeholder="请输入创建时间属性名" />
        </el-form-item>
        <el-form-item label="属性索引最大值" prop="propIndexMax">
          <el-input v-model="form.propIndexMax" placeholder="请输入属性索引最大值" />
        </el-form-item>
        <el-form-item label="修改人属性名" prop="propNameUpdateBy">
          <el-input v-model="form.propNameUpdateBy" placeholder="请输入修改人属性名" />
        </el-form-item>
        <el-form-item label="关系索引最大值" prop="relationIndexMax">
          <el-input v-model="form.relationIndexMax" placeholder="请输入关系索引最大值" />
        </el-form-item>
        <el-form-item label="其他数据" prop="data">
          <el-input v-model="form.data" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="修改时间属性名" prop="propNameUpdateTime">
          <el-input v-model="form.propNameUpdateTime" placeholder="请输入修改时间属性名" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listObject, getObject, delObject, addObject, updateObject, exportObject } from "@/api/rva/object";

export default {
  name: "Object",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 对象表格数据
      objectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        no: null,
        name: null,
        idx: null,
        module: null,
        status: null,
        description: null,
        propNameName: null,
        propNameDel: null,
        propNameNo: null,
        propNameKey: null,
        propNameCreateBy: null,
        uniques: null,
        propNameCreateTime: null,
        propIndexMax: null,
        propNameUpdateBy: null,
        relationIndexMax: null,
        data: null,
        propNameUpdateTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询对象列表 */
    getList() {
      this.loading = true;
      listObject(this.queryParams).then(response => {
        this.objectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        no: null,
        name: null,
        idx: null,
        module: null,
        status: "0",
        description: null,
        propNameName: null,
        propNameDel: null,
        propNameNo: null,
        propNameKey: null,
        propNameCreateBy: null,
        uniques: null,
        propNameCreateTime: null,
        propIndexMax: null,
        propNameUpdateBy: null,
        relationIndexMax: null,
        data: null,
        propNameUpdateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加对象";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getObject(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改对象";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateObject(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addObject(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除对象编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delObject(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有对象数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportObject(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
